home *** CD-ROM | disk | FTP | other *** search
- package horst;
-
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.Rectangle;
- import java.awt.Shape;
- import java.util.Hashtable;
-
- public class TableCell extends View {
- int m_rowSpan;
- int m_colSpan;
- int m_startColumn;
- int m_endColumn;
- int m_startRow;
- int m_endRow;
- int m_width;
- int m_height;
- Color m_bgColor;
- int m_borderSize;
- int m_valign;
- TableRow m_row;
- TableView m_tableView;
- Rectangle m_cellBounds;
-
- public TableCell(View rowViewParent, TableView tableView, Element e, HTMLPane container) {
- super(rowViewParent, e, container);
- this.m_tableView = tableView;
- }
-
- protected int checkWidthHeightAttributes(int axis, int span) {
- if (axis == 1) {
- if (this.m_width != -1 && this.m_width > span) {
- span = this.m_width;
- }
- } else if (this.m_height != -1 && this.m_height > span) {
- span = this.m_height;
- }
-
- return span;
- }
-
- protected int doCellVerticalAlignment(LayoutInfo info) {
- int adjustment = 0;
- Rectangle childrenBounds = super.getBounds();
- if (this.m_cellBounds != null && childrenBounds != null) {
- int cellPadding = this.m_tableView.m_cellPadding;
- if (this.m_valign == 1) {
- int availSpace = this.m_cellBounds.height - 2 * cellPadding - 2 * this.m_borderSize;
- if (availSpace > childrenBounds.height) {
- super.move(0, (availSpace - childrenBounds.height) / 2, true);
- }
- } else if (this.m_valign == 2) {
- int availSpace = this.m_cellBounds.height - 2 * cellPadding - 2 * this.m_borderSize;
- if (availSpace > childrenBounds.height) {
- super.move(0, availSpace - childrenBounds.height, true);
- }
- }
-
- if (info.bPaginate) {
- info.setPageBreak(this.m_cellBounds.y);
- int origHeight = this.m_cellBounds.height;
- super.pageBreakAdjust(info);
- this.m_cellBounds.height = 2 * this.m_borderSize + 2 * this.m_tableView.m_cellPadding + super.m_bounds.height;
- if (origHeight > this.m_cellBounds.height) {
- this.increaseHeight(origHeight - this.m_cellBounds.height);
- }
-
- adjustment = this.m_cellBounds.height - origHeight;
- }
- }
-
- return adjustment;
- }
-
- public Rectangle getBounds() {
- return this.m_cellBounds;
- }
-
- protected int getMinimumSpan(int axis) {
- if (axis == 1) {
- if (super.m_minWidth != -1) {
- return super.m_minWidth;
- } else {
- int paddingAndBorder = 2 * this.m_tableView.m_cellPadding + 2 * this.m_borderSize;
- int var5 = paddingAndBorder + super.getMinimumSpan(1);
- return var5;
- }
- } else if (super.m_minHeight != -1) {
- return super.m_minHeight;
- } else {
- int paddingAndBorder = 2 * this.m_tableView.m_cellPadding + 2 * this.m_borderSize;
- int m_minWidth;
- if (this.m_height >= 0) {
- m_minWidth = this.m_height;
- } else {
- m_minWidth = super.getMinimumSpan(axis);
- }
-
- super.m_minHeight = m_minWidth;
- return super.m_minHeight;
- }
- }
-
- protected int getPreferredSpan(int axis) {
- if (axis == 1) {
- if (super.m_prefWidth != -1) {
- return super.m_prefWidth;
- } else {
- int paddingAndBorder = 2 * this.m_tableView.m_cellPadding + 2 * this.m_borderSize;
- int var6 = paddingAndBorder + super.getPreferredSpan(1);
- if (this.m_width != -1 && this.m_width > 0) {
- if (this.m_width >= var6) {
- var6 = this.m_width;
- } else {
- if (!super.m_bCanWrap) {
- ((View)this).setCanWrap(true);
- }
-
- int minSpan = super.getMinimumSpan(1) + paddingAndBorder;
- if (minSpan <= this.m_width) {
- var6 = this.m_width;
- } else {
- var6 = minSpan;
- }
- }
- }
-
- super.m_prefWidth = var6;
- return super.m_prefWidth;
- }
- } else if (super.m_prefHeight != -1) {
- return super.m_prefHeight;
- } else {
- int paddingAndBorder = 2 * this.m_tableView.m_cellPadding + 2 * this.m_borderSize;
- int span;
- if (this.m_height >= 0) {
- span = this.m_height;
- } else {
- span = super.getPreferredSpan(axis);
- }
-
- super.m_prefHeight = span;
- return super.m_prefHeight;
- }
- }
-
- protected void increaseHeight(int yIncrease) {
- if (this.m_cellBounds != null) {
- Rectangle var10000 = this.m_cellBounds;
- var10000.height += yIncrease;
- }
-
- }
-
- protected void init() {
- this.m_row = (TableRow)super.m_parent;
- this.m_cellBounds = new Rectangle();
- Hashtable atts = super.m_elem.getAttributes();
- this.m_width = Utilities.setIntegerProperty(-1, "width", atts);
- this.m_height = Utilities.setIntegerProperty(-1, "height", atts);
- this.m_bgColor = Utilities.setColorProperty(this.m_row.m_bgColor, "bgcolor", atts);
- this.m_colSpan = Utilities.setIntegerProperty(1, "colspan", atts);
- this.m_rowSpan = Utilities.setIntegerProperty(1, "rowspan", atts);
- this.m_colSpan = Math.max(1, this.m_colSpan);
- this.m_rowSpan = Math.max(1, this.m_rowSpan);
- switch (super.m_elem.getType()) {
- case 4:
- super.m_alignment = 1;
- break;
- default:
- super.m_alignment = Utilities.setAlignmentProperty(false, -1, "align", atts);
- if (super.m_alignment == -1) {
- super.m_alignment = this.m_row.m_alignment;
- }
- }
-
- this.m_valign = Utilities.setAlignmentProperty(true, -1, "valign", atts);
- if (this.m_valign == -1) {
- this.m_valign = this.m_row.m_valign;
- }
-
- }
-
- protected boolean isFloaterClearer() {
- return true;
- }
-
- protected Rectangle layout(int x, int y, int width, LayoutInfo info) {
- int xPos = x + this.m_tableView.m_cellPadding + this.m_borderSize;
- int yPos = y + this.m_tableView.m_cellPadding + this.m_borderSize;
- int space = width - 2 * this.m_tableView.m_cellPadding - 2 * this.m_borderSize;
- space = Math.max(0, space);
- boolean bPaginate = info.bPaginate;
- Rectangle startPageBreak = new Rectangle(info.pageBreak);
- info.bPaginate = false;
- super.layout(xPos, yPos, space, info);
- info.bPaginate = bPaginate;
- info.pageBreak = startPageBreak;
- this.m_cellBounds = new Rectangle(x, y, width, 0);
- if (this.m_height != -1 && this.m_height - 2 * this.m_tableView.m_cellPadding > super.m_bounds.height) {
- this.m_cellBounds.height = this.m_height + 2 * this.m_borderSize;
- } else {
- this.m_cellBounds.height = 2 * this.m_borderSize + 2 * this.m_tableView.m_cellPadding + super.m_bounds.height;
- }
-
- return this.m_cellBounds;
- }
-
- protected void makeChildren(ViewFactory factory) {
- super.makeChildren(factory);
- if (super.m_elem.isAttributeDefined("nowrap")) {
- super.setCanWrap(false);
- }
-
- }
-
- protected void move(int x, int y, boolean bMoveFloaters) {
- if (this.m_cellBounds != null) {
- super.move(x, y, bMoveFloaters);
- Rectangle var10000 = this.m_cellBounds;
- var10000.x += x;
- var10000 = this.m_cellBounds;
- var10000.y += y;
- }
-
- }
-
- protected boolean occupies(int row, int col) {
- return row >= this.m_startRow && row <= this.m_endRow && col >= this.m_startColumn && col <= this.m_endColumn;
- }
-
- protected int pageBreakAdjust(LayoutInfo info) {
- int adjustment = super.pageBreakAdjust(info);
- this.m_cellBounds.height = 2 * this.m_borderSize + 2 * this.m_tableView.m_cellPadding + super.m_bounds.height;
- return adjustment;
- }
-
- public void paint(Graphics g, Shape alloc) {
- Rectangle clip = alloc.getBounds();
- if (this.m_cellBounds.intersects(clip)) {
- if (this.m_bgColor != null) {
- Color oldColor = g.getColor();
- g.setColor(this.m_bgColor);
- g.fillRect(this.m_cellBounds.x, this.m_cellBounds.y, this.m_cellBounds.width, this.m_cellBounds.height);
- g.setColor(oldColor);
- }
-
- super.paint(g, alloc);
- }
-
- }
-
- protected void paintFocusBox(Graphics g, Shape alloc) {
- Rectangle clip = alloc.getBounds();
- if (this.m_cellBounds.intersects(clip)) {
- super.paintFocusBox(g, alloc);
- }
-
- }
-
- protected void setTableColumns(int start) {
- this.m_startColumn = start;
- this.m_endColumn = this.m_startColumn + this.m_colSpan - 1;
- }
-
- protected void setTableRows(int start) {
- this.m_startRow = start;
- this.m_endRow = this.m_startRow + this.m_rowSpan - 1;
- }
- }
-